package serviceset4.restTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import java.util.LinkedHashMap;
import java.util.Map;

public class ServiceSet3Proxy {
    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(commandKey = "SERVICE-SET-3#sampleApi3(String)", fallbackMethod = "reliable")
    public Map sampleApi3(String dependency) {
        String service_uri = "http://SERVICE-SET-3/sampleApi3?dependency={dependency}";
        Map args = new LinkedHashMap();
        args.put("dependency", dependency);

        return restTemplate.getForObject(service_uri, Map.class, args);
    }

    public Map reliable(String dependency) {
        Map result = new LinkedHashMap();

        result.put("provider", "sampleApi3@serviceSet3");
        result.put("dependency", dependency);
        result.put("state", "offline");

        return result;
    }
}
